package cn.edu.hit.configcenter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Wang on 2018/11/15.
 */
@RestController
public class IndexController {
    @Autowired
    HttpServletRequest request;

    @CrossOrigin
    @RequestMapping(method = RequestMethod.GET, value = "/", produces = "text/html;charset=UTF-8")
    public String isRun() {
        return "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\" />\n" +
                "    <title>发电机组远程故障诊断系统</title>\n" +
                "    <script>\n" +
                "        window.baseHost = \"http://" + request.getServerName() + "\";\n" +
                "        window.basePort = " + request.getServerPort() + ";\n" +
                "    </script>\n" +
                "    <script type=\"text/javascript\" src=\"script/fault_web.js\"></script>\n" +
                "    <script src=\"beautifulJson.js\"></script>\n" +
                "</head>\n" +
                "<body></body>\n" +
                "</html>";
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
}
